package com.zsx.shopping.user.controller;

import com.zsx.shopping.common.api.R;
import com.zsx.shopping.common.api.user.dto.LoginDto;
import com.zsx.shopping.common.api.user.dto.RegisterDto;
import com.zsx.shopping.common.session.UserVO;
import com.zsx.shopping.user.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/exist")
    public R<Boolean> exist(@RequestParam String username) {
        return R.success(userService.exist(username));
    }

    @PostMapping("/register")
    public R<Void> register(@RequestBody RegisterDto registerDto) {
        userService.register(registerDto);
        return R.success();
    }

    @PostMapping("/login")
    public R<UserVO> login(@RequestBody LoginDto loginDto) {
        return R.success(userService.login(loginDto));
    }
}
